package com.cr553.gulimall.product.web;

import com.cr553.gulimall.product.vo.Catalog2Vo;
import com.cr553.gulimall.product.entity.CategoryEntity;
import com.cr553.gulimall.product.service.CategoryService;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;

    @Autowired
    RedissonClient redissonClient;


    @GetMapping({"/", "/index"})
    public String index(Model model) {
        List<CategoryEntity> categoryEntities = categoryService.getLevel1Categorys();
        model.addAttribute("categorys", categoryEntities);
        return "index";
    }


    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catalog2Vo>> getCataLogJson() {
        Map<String, List<Catalog2Vo>> catalogJson = categoryService.getCataLogJson();
        return catalogJson;
    }


}
